package com.example.friend.controller.user;

import com.example.common.core.constants.HttpConstants;
import com.example.common.core.controller.BaseController;
import com.example.common.core.domain.Result;
import com.example.common.core.domain.TableDataInfo;
import com.example.common.core.enums.ResultCode;
import com.example.friend.domain.exam.dto.ExamDTO;
import com.example.friend.domain.exam.dto.ExamQueryDTO;
import com.example.friend.service.user.UserExamService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author 23050
 * @version 1.0
 * @description: TODO
 * @date 2025/3/11 19:51
 */
@RestController
@RequestMapping("/user/exam")
public class UserExamController extends BaseController {



    @Resource
    private UserExamService userExamService;


    /**
     * @author 23050
     * @description:  用户报名竞赛
     * @date: 2025/3/11 21:38
     * @param token
     * @param examDTO
     * @return com.example.common.core.domain.Result
     */
    @PostMapping("/enter")
    public Result enter(@RequestHeader(HttpConstants.AUTHENTICATION) String token,
                        @RequestBody ExamDTO examDTO){
        int ret = userExamService.enter(token,examDTO);
        if (ret>0){
            return new Result(ResultCode.SUCCESS.getCode(),"报名成功","");
        }
        return new Result(ResultCode.FAILED.getCode(),"报名失败","");
    }



    /**
     * @author 23050
     * @description:  获取用户已经报名的竞赛列表
     * @date: 2025/3/11 21:38
     * @param examQueryDTO
     * @return com.example.common.core.domain.TableDataInfo
     */
    @GetMapping("/list")
    public TableDataInfo redisList(ExamQueryDTO examQueryDTO){
        return userExamService.redisList(examQueryDTO);
    }






}
